﻿using System.Diagnostics.Contracts;

namespace System.ComponentModel
{
	/// <summary>
	/// Specifies a display name for a class or member.
	/// </summary>
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event)]
	public sealed class DisplayNameAttribute : Attribute
	{
		#region Public Properties
		/// <summary>
		/// Gets the display name.
		/// </summary>
		public string DisplayName
		{
			get
			{
				Contract.Ensures(Contract.Result<string>() != null);

				return displayName;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string displayName;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="DisplayNameAttribute" /> class.
		/// </summary>
		public DisplayNameAttribute(string displayName)
		{
			this.displayName = displayName ?? string.Empty;
		}
		#endregion

		#region Methods
		[ContractInvariantMethod]
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
		private void ObjectInvariant()
		{
			Contract.Invariant(displayName != null);
		}
		#endregion
	}
}